package logic

import (
	"context"
	"jdshopuser/user_srv/model/mysql"

	"jdshopuser/user_srv/internal/svc"
	"jdshopuser/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUsernameInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUsernameInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUsernameInfoLogic {
	return &GetUsernameInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUsernameInfoLogic) GetUsernameInfo(in *user.UserByUsernameRequest) (*user.UserByMobileInfoResponse, error) {
	// todo: 用户By用户名查询信息

	u := mysql.UserWeek3{}
	err := u.UserByUsernameInfo(in.Username)
	if err != nil {
		logx.Error("查询失败", err)
		return nil, err
	}

	return &user.UserByMobileInfoResponse{
		Userid:   int64(u.ID),
		Username: u.Username,
		Password: u.Password,
	}, nil
}
